<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue.js计算属性computed与Vue.js监听属性watch</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
</head>
<body>
    <div id="app">
        {{message.split('').reverse().join('')}}
    </div>
    <script>
        new Vue({
            el:'#app',
            data:{
                message:'Runoob!'
            }
        })
    </script>


    <div id = "app2">
<!--        通过watch监听属性来响应数据的变化-->
        <p style = "font-size:25px;">计数器: {{ counter }}</p>
        <button @click = "counter++" style = "font-size:25px;">点我</button>
    </div>
    <script type = "text/javascript">
        var vm = new Vue({
            el: '#app2',
            data: {
                counter: 1
            }
        });
        vm.$watch('counter', function(nval, oval) {
            // $watch是一个实例方法
            alert('计数器值的变化 :' + oval + ' 变为 ' + nval + '!');
        });
    </script>
</body>
</html>